package com.xc.controller.backend;

import com.xc.common.ServerResponse;
import com.xc.service.IStockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mipha
 * @version 1.0
 * @date 2019/2/27 4:56 PM
 */
@Controller
@RequestMapping("/admin/stock/")
@Slf4j
public class AdminStockController {

    @Autowired
    IStockService iStockService;

    /**
     *      股票列表
     * @param showState
     * @param lockState
     * @param code
     * @param name
     * @param pageNum
     * @param pageSize
     * @param request
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse list(@RequestParam(value = "showState",required = false) Integer showState
            , @RequestParam(value = "lockState",required = false) Integer lockState
            , @RequestParam(value = "code", required = false) String code
            , @RequestParam(value = "name", required = false) String name
            , @RequestParam(value = "pageNum", defaultValue = "1") int pageNum
            , @RequestParam(value = "pageSize", defaultValue = "10") int pageSize
            , HttpServletRequest request){
        return iStockService.listByAdmin(showState ,lockState ,code ,name ,pageNum ,pageSize ,request);
    }


    /**
     *  修改锁定状态
     * @param stockId
     * @return
     */
    @RequestMapping("updateLock.do")
    @ResponseBody
    public ServerResponse updateLock(Integer stockId){
        return iStockService.updateLock(stockId);
    }

    /**
     *  修改显示状态
     * @param stockId
     * @return
     */
    @RequestMapping("updateShow.do")
    @ResponseBody
    public ServerResponse updateShow(Integer stockId){
        return iStockService.updateShow(stockId);
    }


    /**
     *  添加股票
     * @param stockName 股票名
     * @param stockCode 股票代码
     * @param stockType 股票类型    sh 沪股 sz 深股
     * @param isLock    0 不锁定 1 锁定
     * @param isShow    0 显示   1 不显示
     * @return
     */
    @RequestMapping("add.do")
    @ResponseBody
    public ServerResponse add(@RequestParam(value = "stockName", required = false) String stockName
            , @RequestParam(value = "stockCode", required = false) String stockCode
            , @RequestParam(value = "stockType", required = false) String stockType
            , @RequestParam(value = "isLock", required = false) Integer isLock
            , @RequestParam(value = "isShow", required = false) Integer isShow
    ){
        return iStockService.addStock(stockName,stockCode,stockType,isLock,isShow);
    }





    // TODO: 2019/2/27 智能风控股票显示和锁定状态 添加StockMarket表记录






}
